package org.tloss.web.editor.sql.editors;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.tloss.web.editor.model.Sql;
import org.tloss.web.editor.utils.Constants;

public class OrderbyListContentProvider implements ITreeContentProvider {

	@Override
	public void dispose() {

	}

	@Override
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {

	}

	@Override
	public Object[] getChildren(Object arg0) {

		return getElements(arg0);
	}

	

	@Override
	public Object[] getElements(Object arg0) {
		if (arg0 instanceof Sql) {
			Sql sql = ((Sql) arg0);
			if (sql != null && sql.getOrderbies() != null) {
				return sql.getOrderbies().toArray();
			}
			return Constants.EMPTY_ARRAY;
		}
		return  Constants.EMPTY_ARRAY;
	}

	@Override
	public Object getParent(Object arg0) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {
		if (element instanceof Sql) {
			return true;
		}
		return false;
	}

}
